var http = require('http');

var fs = require('fs');

var server = http.createServer().listen(1337, "localhost");

server.on('listening', function(){
	console.log("服务器开始监听");
	// server.close();
});

server.on('connection', function(socket){ 
	console.log("客户端连接已建立");
	console.log(server.timeout);
	// 此处设定server.timeout不生效，超时时间还是5秒
	server.timeout = 20*1000;
	console.log(server.timeout);
});

server.setTimeout(5*1000, function(socket){
	console.log("服务器超时");
	console.log(socket);
});

server.on('close', function(){
	console.log("服务器关闭");
});

server.on('error', function(e){
	if(e.code == 'EADDRINUSE'){
		console.log('服务器地址及端口已被占用');
	}
});